package com.bdsy.business.controller;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bdsy.business.model.ShopFollow;
import com.bdsy.business.service.AuctionShopService;
import com.bdsy.business.service.AuctionTransRecordService;
import com.bdsy.business.service.ShopFollowSevice;

@Controller
@RequestMapping(value = {"${web.adminPath}", "${web.appPath}"})
public class AuctionShopController {

	@Autowired
	private AuctionShopService auctionShopService;
	
	@Autowired
	private AuctionTransRecordService auctionTransRecordService;
	
	@Autowired
	private ShopFollowSevice shopFollowSevice;
	
	
	/**
	 * 
	    * @Title: selectAuctionShop
	    * @Description: 按类别、状态查询竞拍信息
	 */
	@RequestMapping("/selectAuctionShop")
	@ResponseBody
	public Object selectAuctionShop(int shopTypeId, int auctionStatus) {
		
		@SuppressWarnings("rawtypes")
		List<Map> auctionShopList = auctionShopService.selectAuctionShop(shopTypeId, auctionStatus);
		Map<String, Object> map = new LinkedHashMap<>();
		map.put("code", 200);
		map.put("msg", "success");
		map.put("auctionShopList", auctionShopList);
		return map;
	}
	
	/**
	 * 
	    * @Title: auctionShopDetails
	    * @Description: TODO查看竞拍商品详情
	 */
	@RequestMapping("/auctionShopDetails")
	@ResponseBody
	public Object auctionShopDetails(int shopId,String userId) {
		//详情
		List<Map> auctionShop =	auctionShopService.selectAuctionShopDetailsByShopId(shopId);
		//参拍人数
		int totalCount = auctionTransRecordService.count(shopId);
		// 竞拍记录
		List<Map> auctionTransRecord =  auctionTransRecordService.selectAuctionTransRecordByShopId(shopId);
		//是否关注
		List<ShopFollow> ShopFollow = shopFollowSevice.selectShopFollw(userId, shopId);
		int status = 1; //默认关注
		if( null ==  ShopFollow || ShopFollow.size() == 0) {
			status = 0;
		}
		
		Map<String, Object> map = new LinkedHashMap<>();
		map.put("code", 200);
		map.put("msg", "success");
		map.put("auctionShop", auctionShop);
		map.put("totalCount", totalCount);
		map.put("auctionTransRecord", auctionTransRecord);
		map.put("status", status);
		return map;
	}
	
	
/*	@RequestMapping("/add")
	@ResponseBody
	public Object add(AuctionShop auctionShop) {
		boolean result = auctionShopService.add(auctionShop);
		return result;
	}*/
}
